import 'package:flutter/material.dart';
import 'package:flutter_provider_demo/commons/command.dart';
import 'package:flutter_provider_demo/commons/result.dart';
import 'package:flutter_provider_demo/data/repositories/auth_repository.dart';

class LoginViewModel extends ChangeNotifier {
  LoginViewModel({required AuthRepository authRepository}) : _authRepository = authRepository {
    login = Command1<void, (String email, String password)>(_login);
  }

  late Command1 login;
  final AuthRepository _authRepository;

  bool showPassword = false;

  Future<Result<void>> _login((String, String) credentials) async {
    await Future.delayed(const Duration(milliseconds: 300));
    var (username, password) = credentials;
    return _authRepository.login(username, password);
  }

  void taggleShowPassword() {
    showPassword = !showPassword;
    notifyListeners();
  }
}
